/**
 * @created by helin3 2018-04-16
 * @updated by
 * @description 简单模板转换工具
 */
/* global process, exports, __dirname */
/* eslint no-console: 0 */
var fs = require('fs');
var path = require('path');

/**
 * 简单模板替换
 * @param {*} templatePath 模板路径
 * @param {*} outputPath 输出路径
 * @param {*} data 替换数据，仅支持json简单类型
 */
var generator = function(templatePath, outputPath, data) {
  var content = fs.readFileSync(templatePath, 'utf8');
  Object.keys(data).forEach(key => {
    content = content.replace(new RegExp(`{{\\s*${ key }\\s*}}`, 'g'), data[key]);
  });
  fs.writeFileSync(outputPath, content);
};

exports.generator = generator;
